package com.xc.freeapp.service.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.xc.freeapp.dao.RegpatientDao;
import com.xc.freeapp.dao.dataSource.DBContextHolder;
import com.xc.freeapp.entity.Regpatient;
import com.xc.freeapp.exception.BaseException;
import com.xc.freeapp.service.RegpatientService;
import com.xc.freeapp.util.Constant;

@Service
public class RegpatientServiceImpl implements RegpatientService {
	Logger log = Logger.getLogger(this.getClass());
	@Autowired
	private RegpatientDao regpatientDao;
	public int deleteByPrimaryKey(Integer id) {
		DBContextHolder.switchDataSourceRW();//切换数据源
		return regpatientDao.deleteByPrimaryKey(id);
	}
	public int insert(Regpatient record) throws BaseException {
		DBContextHolder.switchDataSourceRW();//切换数据源
		int count ;
		Regpatient regpatient = regpatientDao.selectByVid(record.getCreateby(), record.getPatientdentityno());
		if(regpatient!=null){
			log.info("插入就诊人失败,就诊人已经存在");
			throw new BaseException(Constant.ERRORCODE_557);
		}
		try{
			count= regpatientDao.insertSelective(record);
		}catch(Exception e){
			
			throw new BaseException(Constant.ERRORCODE_557);
		}
		return count;
	}

	public Regpatient selectByPrimaryKey(Integer id) {
		DBContextHolder.switchDataSourceRW();//切换数据源
		return regpatientDao.selectByPrimaryKey(id);
	}

	public int updateByPrimaryKey(Regpatient record) {
		DBContextHolder.switchDataSourceRW();//切换数据源
		return regpatientDao.updateByPrimaryKey(record);
	}
	public List<Regpatient> selectByUserId(Integer  userid,PageBounds pageBounds) {
		DBContextHolder.switchDataSourceRW();//切换数据源
		return regpatientDao.selectByUserId(userid, pageBounds);
	}

}
